package cn.bo.cloud.common.redis.handle;


import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.connection.Message;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
public class DefaultRedisKeyExpirationProcessor implements RedisKeyExpirationProcessor{
    private static final Logger logger = LoggerFactory.getLogger(DefaultRedisKeyExpirationProcessor.class);


    @Override
    public void onMessage(Message message, byte[] pattern) {
        // 用户做自己的业务处理即可,注意message.toString()可以获取失效的key
        String expiredKey = Optional.ofNullable(message).orElse(null).toString();
        if(StringUtils.isNotEmpty(expiredKey) && !"null".equals(expiredKey)){
            logger.info(expiredKey);
        }
    }
}
